<?php
class Node{
    public $data;
    public $lchild=null;
    public $rchild=null;

    public function __construt($data=''){
        $this->data=$data;
    }
}

class Tree{
    public $root;
    public static $string='ABC##DE#G##F###';
    public static $index=0;

    public function __construct(){
        $this->root=new Node();
    }


    public static function createTree(&$node=''){
        $ch =self::$string[self::$index];
        self::$index++;
        if($ch==='#'){
            $node=null;
        }else{
            if(!$node){
                $node=new Node();
            }
            $node->data=$ch;
            echo $node->data;
            self::createTree($node->lchild);
            self::createTree($node->rchild);
        }

        return true;
    }

    public static function preTraver($node){
        if($node){
            echo $node->data;
            echo $node->lchird->data;
          /*  self::preTraver($tree->lchird);
            self::preTraver($tree->rchird);*/
        }
    }
}


$tree = new Tree();
Tree::createTree($tree->root);
echo '</br>';
echo $tree->root->data;
echo $tree->root->lchild->data;
echo $tree->root->lchild->lchild->data;
echo $tree->root->lchild->rchild->data;
echo $tree->root->lchild->rchild->lchild->data;
echo $tree->root->lchild->rchild->rchild->data;
echo $tree->root->lchild->rchild->lchild->rchild->data;
echo '</br>';
Tree::preTraver($tree->root);
?>